package com.sinbader.xiaole.admin.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import com.sinbader.xiaole.common.entity.StockLog;
import com.sinbader.xiaole.common.model.params.StockLogParam;
import com.sinbader.xiaole.common.service.StockLogService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;


/**
 * 库存变更记录控制器
 *
 */
@Api("库存变更记录")
@Controller
@RequestMapping("/stockLog")
public class StockLogController extends BaseController {

    private String PREFIX = "/stockLog";

    @Autowired
    private StockLogService stockLogService;

    /**
     * 跳转到主页面
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/stockLog.html";
    }

    /**
     * 新增页面
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/stockLog_add.html";
    }

    /**
     * 编辑页面
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/stockLog_edit.html";
    }

    @ApiOperation(value = "新增")
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(StockLogParam stockLogParam) {
        this.stockLogService.add(stockLogParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "编辑")
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(StockLogParam stockLogParam) {
        this.stockLogService.update(stockLogParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "删除")
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(StockLogParam stockLogParam) {
        this.stockLogService.delete(stockLogParam);
        return ResponseData.success();
    }

    @ApiOperation(value = "查看详情")
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(StockLogParam stockLogParam) {
        StockLog detail = this.stockLogService.getById(stockLogParam.getId());
        return ResponseData.success(detail);
    }

    @ApiOperation(value = "查询列表")
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(StockLogParam stockLogParam) {
        return this.stockLogService.findPageBySpec(stockLogParam);
    }

}
